/*
* $Id: AddFamilyOperation.cpp 154 2010-09-27 08:10:48Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "AddFamilyOperation.h"
#include "FieldValuesOperation.h"
#include "Database/Tables/FamiliesTable.h"
#include "Database/Tables/TableNames.h"
#include "Database/SqlBinder.h"

CAddFamilyOperation::CAddFamilyOperation(){}
CAddFamilyOperation::~CAddFamilyOperation(){}

CAddFamilyOperation::content::content(){
	Clear();
}
void CAddFamilyOperation::content::Clear(){
	s_nIdPoint = 0;
	s_nType = Family::DEFAULT;
	s_nId = 0;
	s_nIdHousing = 0;
	s_nIdRecord = 0;
	s_strName.clear();
	s_strNote.clear();
	s_aUserFields.clear();
}

void CAddFamilyOperation::AddValue(IDatabase* pDatabase){
	CFieldValuesOperation fvOper;
	fvOper.m_content.s_aUserFields = m_content.s_aUserFields;
	fvOper.m_content.s_table = TypeField::FAMILIES;
	fvOper.AddValue(pDatabase);
	CFamiliesTable families;
	families.m_content.s_strName = m_content.s_strName;
	families.m_content.s_nIdPoint = m_content.s_nIdPoint;
	families.m_content.s_type = m_content.s_nType;
	families.m_content.s_strNote = m_content.s_strNote;
	families.m_content.s_nIdRecord = fvOper.m_content.s_nId;
	families.SetValue(pDatabase);
	m_content.s_nId = families.m_content.s_nId;
	m_content.s_nIdRecord = fvOper.m_content.s_nId;

	std::tstring strRequest(_T("UPDATE "));
	CSqlBinder binder(strRequest + HOUSINGS_TABLE_NAME + 
		_T(" SET id_family=? WHERE id_housing=?"));
	binder.SetValue(0, m_content.s_nId);
	binder.SetValue(1, m_content.s_nIdHousing);
	pDatabase->ExecRequest(binder.GetRequest());
}